//
//  XHMyQrCodeViewController.m
//  umibus
//
//  Created by 冷山 on 16/6/17.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "XHMyQrCodeViewController.h"

#import "Services.h"

@interface XHMyQrCodeViewController ()
@property (weak, nonatomic) IBOutlet UIButton *ui_copyButton;
@property (weak, nonatomic) IBOutlet UILabel *ui_code;
@property (weak, nonatomic) IBOutlet UILabel *ui_content;

@property (strong, nonatomic) NSDictionary * m_invitecode;

@end

@implementation XHMyQrCodeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.ui_copyButton.layer.masksToBounds = YES;
    self.ui_copyButton.layer.cornerRadius = 8;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self getInvitecode];
}

- (void)getInvitecode
{
    self.ui_copyButton.userInteractionEnabled=NO;
    [ServiceManager getStudentCarCodeWithSuccess:^(NSDictionary *data) {
        self.ui_copyButton.userInteractionEnabled=YES;
        self.m_invitecode = data;
        if ([self.m_invitecode[@"inviteCode"] isKindOfClass:[NSString class]])
        {
            self.ui_code.text = [NSString stringWithFormat:@"%@",self.m_invitecode[@"inviteCode"]];
        }
        else
        {
            self.ui_code.text = @"";
        }
        if ([self.m_invitecode[@"inviteShip"] isKindOfClass:[NSArray class]])
        {
            NSArray * array = self.m_invitecode[@"inviteShip"];
            NSString * l1 = @"";
            NSString * l2 = @"";
            NSString * l3 = @"";
            for (NSDictionary * dic in array)
            {
                if ([dic[@"inviteLevel"] isEqualToString:@"1"])
                {
                    l1 = [NSString stringWithFormat:@"%@",dic[@"inviteCount"]];
                }
                else if ([dic[@"inviteLevel"] isEqualToString:@"2"])
                {
                    l2 = [NSString stringWithFormat:@"%@",dic[@"inviteCount"]];
                }
                else if ([dic[@"inviteLevel"] isEqualToString:@"3"])
                {
                    l3 = [NSString stringWithFormat:@"%@",dic[@"inviteCount"]];
                }
            }
            if (![NSString checkNullString:l1]&&
                ![NSString checkNullString:l2]&&
                ![NSString checkNullString:l3])
            {
                self.ui_content.text = [NSString stringWithFormat:@"一级用户:%@人|二级用户:%@人|三级用户:%@人",l1,l2,l3];
            }
            else if (![NSString checkNullString:l1]&&
                     ![NSString checkNullString:l2]&&
                      [NSString checkNullString:l3])
            {
                self.ui_content.text = [NSString stringWithFormat:@"一级用户:%@人|二级用户:%@人",l1,l2];
            }
            else if (![NSString checkNullString:l1]&&
                      [NSString checkNullString:l2]&&
                      [NSString checkNullString:l3])
            {
                self.ui_content.text = [NSString stringWithFormat:@"一级用户:%@人",l1];
            }
            
        }
        else
        {
            self.ui_content.text = @"";
        }
        
    } failure:^(NSDictionary *data) {
        self.ui_copyButton.userInteractionEnabled=NO;
    }];
}
- (IBAction)copyAction:(id)sender
{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.ui_code.text;
    [PromptAction showSuccessPrompt:@"复制推荐码成功"];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
